home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1998 August / PC Plus SuperCD 50a Issue 142 (CD142a) (August 1998).iso / trial / demon / TURNPIKE.1 / CLASSES.ZIP / JAVA / NET / Socket.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-04-14  |  2.4 KB  |  98 lines

  1. package java.net;
  2.  
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5. import java.io.OutputStream;
  6.  
  7. public final class Socket {
  8.    SocketImpl impl;
  9.    private static SocketImplFactory factory;
  10.  
  11.    Socket() {
  12.       this.impl = (SocketImpl)(factory != null ? factory.createSocketImpl() : new PlainSocketImpl());
  13.    }
  14.  
  15.    public Socket(String var1, int var2) throws UnknownHostException, IOException {
  16.       this(var1, var2, true);
  17.    }
  18.  
  19.    public Socket(String var1, int var2, boolean var3) throws IOException {
  20.       this();
  21.       String var4 = new String(var1);
  22.       SecurityManager var5 = System.getSecurityManager();
  23.       if (var5 != null) {
  24.          var4 = InetAddress.getByName(var4).getHostAddress();
  25.          var5.checkConnect(var4, var2);
  26.       }
  27.  
  28.       try {
  29.          this.impl.create(var3);
  30.          this.impl.connect(var4, var2);
  31.       } catch (IOException var7) {
  32.          this.impl.close();
  33.          throw var7;
  34.       }
  35.    }
  36.  
  37.    public Socket(InetAddress var1, int var2) throws IOException {
  38.       this(var1, var2, true);
  39.    }
  40.  
  41.    public Socket(InetAddress var1, int var2, boolean var3) throws IOException {
  42.       this();
  43.       SecurityManager var4 = System.getSecurityManager();
  44.       if (var4 != null) {
  45.          var4.checkConnect(var1.getHostAddress(), var2);
  46.       }
  47.  
  48.       try {
  49.          this.impl.create(var3);
  50.          this.impl.connect(var1, var2);
  51.       } catch (SocketException var6) {
  52.          this.impl.close();
  53.          throw var6;
  54.       }
  55.    }
  56.  
  57.    public InetAddress getInetAddress() {
  58.       return this.impl.getInetAddress();
  59.    }
  60.  
  61.    public int getPort() {
  62.       return this.impl.getPort();
  63.    }
  64.  
  65.    public int getLocalPort() {
  66.       return this.impl.getLocalPort();
  67.    }
  68.  
  69.    public InputStream getInputStream() throws IOException {
  70.       return this.impl.getInputStream();
  71.    }
  72.  
  73.    public OutputStream getOutputStream() throws IOException {
  74.       return this.impl.getOutputStream();
  75.    }
  76.  
  77.    public synchronized void close() throws IOException {
  78.       this.impl.close();
  79.    }
  80.  
  81.    public String toString() {
  82.       return "Socket[addr=" + this.impl.getInetAddress() + ",port=" + this.impl.getPort() + ",localport=" + this.impl.getLocalPort() + "]";
  83.    }
  84.  
  85.    public static synchronized void setSocketImplFactory(SocketImplFactory var0) throws IOException {
  86.       if (factory != null) {
  87.          throw new SocketException("factory already defined");
  88.       } else {
  89.          SecurityManager var1 = System.getSecurityManager();
  90.          if (var1 != null) {
  91.             var1.checkSetFactory();
  92.          }
  93.  
  94.          factory = var0;
  95.       }
  96.    }
  97. }
  98.